package edu.szcu.vitaguard.dao;

import edu.szcu.vitaguard.entity.Department;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 科室DAO接口
 */
@Mapper
public interface DepartmentDao {

    /**
     * 插入科室
     * @param department 科室对象
     * @return 影响的行数
     */
    @Insert("INSERT INTO department(dept_name, description, status, create_time, update_time) " +
            "VALUES(#{deptName}, #{description}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "deptId")
    int insert(Department department);

    /**
     * 根据ID查询科室
     * @param deptId 科室ID
     * @return 科室对象
     */
    @Select("SELECT * FROM department WHERE dept_id = #{deptId}")
    Department selectById(Integer deptId);

    /**
     * 查询所有科室
     * @return 科室列表
     */
    @Select("SELECT * FROM department")
    List<Department> selectAll();

    /**
     * 根据状态查询科室
     * @param status 状态
     * @return 科室列表
     */
    @Select("SELECT * FROM department WHERE status = #{status}")
    List<Department> selectByStatus(Integer status);

    /**
     * 更新科室
     * @param department 科室对象
     * @return 影响的行数
     */
    @Update("UPDATE department SET dept_name = #{deptName}, description = #{description}, " +
            "status = #{status}, update_time = #{updateTime} WHERE dept_id = #{deptId}")
    int update(Department department);

    /**
     * 删除科室
     * @param deptId 科室ID
     * @return 影响的行数
     */
    @Delete("DELETE FROM department WHERE dept_id = #{deptId}")
    int deleteById(Integer deptId);
}
